<?php 
/* SVN FILE: $Id$ */
/* LoginController Test cases generated on: 2009-10-30 09:52:59 : 1256863979*/
App::import('Controller', 'Login');

class LoginTestController extends LoginController {
	var $autoRender = false;
	var $name = 'Login';
    var $viewPath = "Login";
	
	function redirect($url=NULL,$code=NULL) { 
		$this->lastRedirectUrl = $url; 
		$action = $this->params['action'];
		#debug("$action action redirects to $url");
		$this->Session->write('test.lastRedirectUrl',$url);
		#debug($this->params);
		return true;
	}
}

class LoginControllerTest extends CakeTestCase {
	var $Login = null;

	function startTest() {
		#runkit_method_redefine("LoginController" , "redirect"  , '$url, $status = null, $exit = true'  , "return true;" );
		$this->Login = new LoginController();
		$this->Login->constructClasses();
	}
	function testLoginControllerInstance() {
		$this->assertTrue(is_a($this->Login, 'LoginController'));
	}
	function testIndexWithoutLogin() {
		echo("<p>IndexWithoutLogin</p>");
		$this->testLogout(); # ブラウザから実行されるのでからなずログアウトを一回コールしてセッションを消す
		$result = $this->testAction('/admin/login/',array('redirect' => 'false'));
		$this->assertEqual($this->Login->Session->read('test.lastRedirectUrl'),'/admin/login/login');
		#debug($result);
	} 
	function testIndexWithValidUser() {
		echo("<p>testIndexWithValidUser</p>");
		$this->testLogout(); 
		$this->testLoginWithValidUser(); 
		$result = $this->testAction('/admin/login/',array('redirect' => 'false'));
		#debug($result);
	} 
	#function testLoginControllerLogin() {
		#$result = $this->testAction('/admin/login/login',array('return'=>'vars'));
		#$flash = $this->Login->Session->read('auth');
		#debug($flash['message']);
		#$this->assertEqual($flash['message'],'ログインしてください');
		#debug($result);
	#} 
	function testLogout() {
		#$this->testLoginWithValidUser();
		$result = $this->testAction('/admin/login/logout',array('redirect'=>'false'));
	} 
	function testLoginWithInvalidUser(){
		echo("<p style='font-size:12pt;margin:0.5em'><b>ログイン：無効なユーザ</b></p>");
		$data = array(
  		  	"User" => array(
       			 "name" => "foo",
       			 "hashed_password" => "bar",
    		),
		);
		$result = $this->testAction('/admin/login/login', array(
    		'data' => $data,
    		'fixturize' => false,
    		'method' => 'post',
    		'return' => 'vars')
		);
		#ユーザ／パスワードの組み合わせが無効です
		#$flash = $this->Login->Session->read('Message.flash');
		#debug($flash['message']);
		#$this->assertEqual($flash['message'],'ユーザ／パスワードの組み合わせが無効です');
		#debug($result);
	}
	function _testLoginWithInvalidPassword(){
		$data = array(
  		  	"User" => array(
       			 "name" => "dave",
       			 "hashed_password" => "bar",
    		),
		);
		$result = $this->testAction('/admin/login/login', array(
    		'data' => $data,
    		'fixturize' => false,
    		'method' => 'post',
    		'return' => 'render')
		);
		#debug($result);
	}
	function testLoginWithValidUser(){
		echo("<p style='font-size:12pt;margin:0.5em'><b>testLoginWithValidUser()</b></p>");
		$data =array(
  		  	"User" => array(
       			 "name" => "dave",
       			 "hashed_password" => "dave",
    		),
		);
		$result = $this->testAction('/admin/login/login', array(
    		'data' => $data,
    		'fixturize' => false,
    		'method' => 'post',
    		'return' => 'results','redirect' => 'false')
		);
		$this->assertEqual($this->Login->Session->read('test.lastRedirectUrl'),'/admin/login/index');
		#debug($result);
	}
	function endTest() {
		unset($this->Login);
	}
}
?>